<template>
  <div class="license">
    <div class="h-table" style="margin: auto;border-top:none;">
      <table>
        <tr>
          <td>授权应用：</td>
          <td>{{ title }}</td>
        </tr>
        <tr>
          <td>授权用户：</td>
          <td>{{ detail.user }}</td>
        </tr>
        <tr>
          <td>到期时间：</td>
          <td>{{ dateFormat(Number(detail.date)) }}</td>
        </tr>
        <tr>
          <td>序 列 号：</td>
          <td>{{ detail.sn }}</td>
        </tr>
        <tr>
          <td colspan="2" align="center">
            <FileInput accept="license.dat" @change="uploadLicense">
              <Button text>更新授权文件</Button>
            </FileInput>
          </td>
        </tr>
      </table>
    </div>
  </div>
  <Prompt type="password" title="请输入管理员密码" ref="pwdInput"></Prompt>
</template>

<script setup>
import {ajax, format} from 'framework'
import {reactive,ref} from 'vue'



const title = document.title
const dateFormat = format('yyyy-MM-dd hh:mm')
const detail = reactive({}),pwdInput=ref(null)
ajax.get('license/detail').then(r => {
  Object.assign(detail, r.data)
})
const uploadLicense=(file)=>{
  //最大50K
  if(!file||file.size>50*1024){
    HeyUI.alert("文件过大")
    return
  }
  pwdInput.value.show().then(r=>{
    ajax.upload('license/update?password='+r,{
      file:file
    }).then(r=>{
      if(r.data=='更新成功'){
        ajax.get('license/detail').then(r => {
          Object.assign(detail, r.data)
        })
        HeyUI.message(r.data)
      }else{
        HeyUI.message.error(r.data)
      }

    })
  })
}
</script>

<style>
html, body, #app {
  width: 100%;
  height: 100%;
}

.license {
  display: flex;
  align-items: center;
  height: 100%;
  font-size: 1.5rem;
}
</style>
